﻿
@{
    ViewBag.Title = "用户登录 - 果壳园";
    Layout = "~/Areas/Admin/Views/Shared/_AccountLayout.cshtml";
}
@model Nutshell.Blog.Model.ViewModel.UserLogin
<h2 class="title">用户登录</h2>
<div class="left">
    @using (Ajax.BeginForm("/signin", new { returnUrl = ViewBag.Return }, new AjaxOptions() { OnBegin = "login_begin", OnSuccess = "login_success", OnFailure = "login_failure" }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true, "", new { @class = "error" })
        <div class="ctrl-group">
            @Html.LabelFor(model => model.UserName)
            <div>
                @Html.TextBoxFor(m => m.UserName, new { id = "user-name", placeholder = "请输入账号", maxlength = "20" })
            </div>
            @Html.ValidationMessageFor(m => m.UserName, null, new { @class = "error" })
        </div>
        <div class="ctrl-group">
            @Html.LabelFor(model => model.Password)
            <div>
                @Html.PasswordFor(m => m.Password, new { id = "user-pwd", placeholder = "请输入密码", maxlength = "20" })
            </div>
            @Html.ValidationMessageFor(m => m.Password, null, new { @class = "error" })
        </div>
        <div class="ctrl-group">
            @Html.LabelFor(model => model.ValidCode)
            <div id="code_box">
                @Html.TextBoxFor(m => m.ValidCode, new { id = "txtCode", placeholder = "请输入验证码", maxlength = "20" })
            </div>
            @Html.ValidationMessageFor(m => m.ValidCode, null, new { @class = "error" })
            <img id="img_code" title="点击更换验证码" src="/account/getValidCode" alt="验证码加载失败" onclick="changecode()" />
        </div>
        <div class="ctrl-btns" style="text-align:center;">
            <input type="submit" id="btnLogin" value="登录" class="btn-submit" />

            <p>
                <a href="/account/register">还没有账号？请先注册。</a>
                <a href="/account/forgetpassword">忘记密码？</a>
            </p>
        </div>
    }
</div>
@section script{
    <script>
        function login_begin() {
            btn_loading('登录中');
        }
        
        var login_success = function (data) {
            btn_loaded('登录');
            if (data.code == 0) {
                location = data.url;
            } else if (data.code == 4) {
                alert(data.msg);
                location = data.url;
            } else {
                alert(data.msg);
                changecode();
            }
        }
        function login_failure() {
            btn_loaded('登录');
        }
        
        
    </script>
}